<template>
    <div class="wrapper" ref="wrapper">
        <div>
            <div class="area">
                <div class="title">当前城市</div>
                <div class="butList">
                    <div class="cityButton act">{{this.$store.state.city}}</div>
                </div>
            </div>
            <div class="area">
                <div class="title">热门城市</div>
                <div class="butList">
                    <div class="cityButton" v-for="item in hotCity" :key="item.id" @click="changeCity(item.name)">{{item.name}}</div>
                </div>
            </div>
            <div class="area" v-for="(item,key) in cityList" :key="key" :ref="key">
                <div class="title">{{key}}</div>
                <div class="cityList">
                    <div class="cityItem border-bottom" v-for="it in item" :key="it.id" @click="changeCity(it.name)">{{it.name}}</div>
                </div>
            </div>
        </div>
    </div>
</template>

<style scoped>
.wrapper{
    overflow: hidden;
    position: absolute;
    top: 1.74rem;
    left: 0;
    bottom: 0;
}
.area{
    width: 100%;
}
.title{
    background-color: #ededed;
    padding: .15rem;
}
.butList{
    box-sizing: border-box;
    width: 100%;
    padding: .2rem;
}

.cityButton{
    display: inline-block;
    border:1px solid #d6d6d6;
    border-radius: .05rem;
    padding: .1rem .4rem;
    margin: .1rem;
}
.act{
    color: #57a3d2;
    border: 1px solid #57a3d2;
}
.cityList{
    width: 100%;
}
.cityItem{
    box-sizing: border-box;
    padding: .2rem;
}
</style>

<script>
import BScroll from 'better-scroll'

export default {
    data(){
        return{
            title:"列表",
            aaa:4,
        }
    },
    watch:{
        actAlp(){
            var target=this.$refs[this.actAlp][0];
            this.scroll.scrollToElement(target,500)
        }
    },
    props:['hotCity','cityList','actAlp'],
    methods:{
        changeCity(city){
            this.$store.commit("change",city);
            this.$router.push("/");
        }
    },
    mounted(){
        // let wrapper = document.querySelector('.wrapper')
        this.scroll = new BScroll(this.$refs.wrapper);
    }
}
</script>


